package com.jiang.smartdangjian.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.tabs.TabLayout;
import com.jiang.smartdangjian.R;
import com.jiang.smartdangjian.tool.MyAdapter;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.Arrays;
import java.util.List;

public class S1Activity extends BaseActivity {

    private Banner banner2;
    private CardView cv;
    private TabLayout tabLayout2;
    private RecyclerView rv;
    List<Integer> resList1 = Arrays.asList(R.drawable.x1, R.drawable.hd5, R.drawable.x3);
    List<Integer> resList2 = Arrays.asList(R.drawable.x1, R.drawable.x2, R.drawable.x4);
    List<Integer> resList3 = Arrays.asList(R.drawable.s1, R.drawable.s2, R.drawable.x1);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_s1);
        initView();

        setTitle("党员学习");
        setUI(resList1);
    }

    private void initView() {
        banner2 = (Banner) findViewById(R.id.banner2);
        cv = (CardView) findViewById(R.id.cv);
        tabLayout2 = (TabLayout) findViewById(R.id.tabLayout2);
        rv = (RecyclerView) findViewById(R.id.rv);

        rv.setLayoutManager(new LinearLayoutManager(getThis()));
        banner2.setImages(Arrays.asList(R.drawable.x1, R.drawable.x2, R.drawable.x3))
                .setImageLoader(new ImageLoader() {
                    @Override
                    public void displayImage(Context context, Object o, ImageView imageView) {
                        imageView.setImageResource((Integer) o);
                    }
                }).start();
        tabLayout2.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() == 0) {
                    setUI(resList1);
                } else if (tab.getPosition() == 1) {
                    setUI(resList2);
                } else {
                    setUI(resList3);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
    private void setUI(List<Integer> resList) {
        rv.setAdapter(new MyAdapter<Integer>(getThis(), R.layout.item_kechen, resList) {
            private ImageView imageView4;
            private TextView textView4;
            private TextView textView15;
            private TextView textView13;
            private TextView textView14;
            private TextView textView16;

            @Override
            public void init(View root, int position) {
                imageView4 = (ImageView) root.findViewById(R.id.imageView4);
                textView4 = (TextView) root.findViewById(R.id.textView4);
                textView15 = (TextView) root.findViewById(R.id.textView15);
                textView13 = (TextView) root.findViewById(R.id.textView13);
                textView14 = (TextView) root.findViewById(R.id.textView14);
                textView16 = (TextView) root.findViewById(R.id.textView16);
                imageView4.setImageResource(list.get(position));
                root.setOnClickListener(v -> {
                    startActivity(new Intent(getThis(), S1D1Activity.class));
                });
            }
        });
    }
}